package com.ruoyi.web.controller.material.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.controller.material.entity.request.SupplierAddRequest;
import com.ruoyi.web.controller.material.entity.request.SupplierPageRequest;
import com.ruoyi.web.controller.material.entity.request.warehouseAddRequest;
import com.ruoyi.web.controller.material.entity.request.warehousePageRequest;
import com.ruoyi.web.controller.material.entity.ylSupplier;
import com.ruoyi.web.controller.material.entity.ylWarehouse;
import com.ruoyi.web.controller.material.service.WarehouseService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * 仓库管理信息Controller
 *
 * @author jzx
 * @date 2025-10-21
 */

@RestController
@RequestMapping("/admin/Warehouse")
public class WarehouseController extends BaseController {
    //ylWarehouse
    @Resource
    private WarehouseService warehouseService;

    @PermitAll
    @Anonymous
    @GetMapping("/page")  // /admin/Supplier/page
    @Operation(summary = "列表查询")
    public TableDataInfo getPage(warehousePageRequest warehousePageRequest) {
        startPage();
        List<ylWarehouse> list = warehouseService.getPage(warehousePageRequest);
        return getDataTable(list);
    }

    @PermitAll
    @Anonymous
    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public AjaxResult delete(@PathVariable Long[] id) {
        warehouseService.delete(id);
        return success();
    }

    @PermitAll
    @Anonymous
    @PostMapping("/add")
    @Operation(summary = "新增仓库")
    public AjaxResult add(@Validated @RequestBody warehouseAddRequest warehouseAddRequest) {
        warehouseService.add(warehouseAddRequest);
        return success();
    }


    @GetMapping(value = "/{id}")
    @Operation(summary = "查询明细")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(warehouseService.selectById(id));
    }

    @PermitAll
    @Anonymous
    @PostMapping("/update")
    @Operation(summary = "修改仓库")
    public AjaxResult update(@Validated @RequestBody warehouseAddRequest warehouseUpdateRequest) {
        warehouseService.update(warehouseUpdateRequest);
        return success();
    }
}
